package com.mxpio.boot.dbconsole.api.conf;

import com.mxpio.framework.security.base.service.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @创建人 gewenzhen
 * @创建时间 2024/12/31
 * @描述
 */
@Configuration
@ConditionalOnProperty(name = "mxpio.cloudModel", havingValue = "true")
public class DbconsoleCloudServiceConfig {
    @DubboReference
    UserService userService;
    @DubboReference
    GrantedAuthorityService grantedAuthorityService;
    @DubboReference
    RbacCacheService rbacCacheService;
    @DubboReference
    DataResourceService dataResourceService;
    @DubboReference
    DeptService deptService;
    @DubboReference
    OnlineUserService onlineUserService;

    @Bean
    @ConditionalOnMissingBean(UserService.class)
    public UserService remoteUserService() {
        if(userService == null){
            System.out.println("userService is null");
        }
        return userService;
    }

    @Bean
    @ConditionalOnMissingBean(GrantedAuthorityService.class)
    public GrantedAuthorityService remoteGrantedAuthorityService() {
        return grantedAuthorityService; // 注入远程服务
    }

    @Bean
    @ConditionalOnMissingBean(RbacCacheService.class)
    public RbacCacheService remoteRbacCacheService() {
        return rbacCacheService; // 注入远程服务
    }

    @Bean
    @ConditionalOnMissingBean(DataResourceService.class)
    public DataResourceService remoteDataResourceService() {
        return dataResourceService; // 注入远程服务
    }

    @Bean
    @ConditionalOnMissingBean(DeptService.class)
    public DeptService remoteDeptService() {
        return deptService; // 注入远程服务
    }

    @Bean
    @ConditionalOnMissingBean(OnlineUserService.class)
    public OnlineUserService remoteOnlineUserService() {
        return onlineUserService; // 注入远程服务
    }
}
